<script>
const arr = [1, 2, 3, 4, [1, 2, 3, [1, 2, 3, [1, 2, 3]]], 5, "string", { name: "盖伦" }]

let flatArr = []
function myflat(arr){
    arr.forEach(item => {
        if(Array.isArray(item)){
            myflat(item)
        }else{
            flatArr.push(item)
        }
    })
}

myflat(arr)
console.log(flatArr)

</script>